package com.zide.member.service.community.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zide.common.core.domain.PageResult;
import com.zide.member.entity.knowledge.CommunityCategory;
import com.zide.member.mapper.community.CommunityCategoryMapper;
import com.zide.member.mapper.community.CommunityEssayMapper;
import com.zide.member.service.community.CommunityCategoryService;
import com.zide.member.vo.result.community.CommCategoryResultVO;
import com.zide.member.vo.save.community.CommCategorySaveVO;
import com.zide.member.vo.search.community.CommCategorySearchVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 石添添
 * @description
 * @date 2024-09-09 21:56
 */
@RequiredArgsConstructor
@Service
@Slf4j
public class CommunityCategoryServiceImpl implements CommunityCategoryService {

    private final CommunityCategoryMapper communityCategoryMapper;
    private final CommunityEssayMapper communityEssayMapper;

    /**
     * 分页查询分类列表
     */
    @Override
    public PageResult<CommCategoryResultVO> pageList(CommCategorySearchVO searchVO) {
        return null;
    }

    /**
     * 查询分类列表
     */
    @Override
    public List<CommCategoryResultVO> searchList(CommCategorySearchVO searchVO) {
        LambdaQueryWrapper<CommunityCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CommunityCategory::getParentId,searchVO.getParentId()).orderByAsc(CommunityCategory::getSorts);
        List<CommunityCategory> dbResult = communityCategoryMapper.selectList(wrapper);
        if(CollectionUtil.isNotEmpty(dbResult)) {
            return BeanUtil.copyToList(dbResult,CommCategoryResultVO.class);
        }
        return List.of();
    }

    /**
     * 查询分类详情
     */
    @Override
    public CommCategoryResultVO searchDetail(Long id) {
        return null;
    }

    @Override
    public int removeCategory(Long[] ids) {
        return communityEssayMapper.deleteBatchIds(List.of(ids));
    }

    /**
     * 修改分类
     */
    @Override
    public int modifyCategory(CommCategorySaveVO saveVO) {
        return 0;
    }

    /**
     * 添加分类
     */
    @Override
    public int addCategory(CommCategorySaveVO saveVO) {
        return 0;
    }


}
